package pl.ydp.components.mathcell.mathcell.preprocessing.structures
{
	import flash.geom.Point;	
	import pl.ydp.components.mathcell.mathrecognizer.characters.Character;
	
	/** 
	 * This class is responsible for processing arrays.
	 * Contains static functionalities.
	 */
	public class ArrayProcessor
	{
		
		public static function cloneRecursive(source:Array):Array{
			var output:Array = new Array();
			
			for each (var obj:Object in source){
				//var type:* = typeof obj;
				if (obj is Array)
					output.push(cloneRecursive(obj as Array));
				else if (obj is Point)
					output.push((obj as Point).clone());
				else if (obj is String)
					output.push(obj as String);
				else if (obj is Character)
					output.push(new Character((obj as Character).symbol));
				/*else  CSX if (obj is MathGridEditorCellContent){
					var sourceMGECC:MathGridEditorCellContent = obj as MathGridEditorCellContent;
					var mgecc:MathGridEditorCellContent = new MathGridEditorCellContent(sourceMGECC.text, sourceMGECC.open);
					mgecc.length = sourceMGECC.length;
					output.push(mgecc);
				}*/
			}
			
			return output;
		}
		
		public static function compare(arr1:Array, arr2:Array):Boolean{
			
			if (arr1.length != arr2.length)
				return false;
			
			for (var e:Number = 0 ; e < arr1.length ; e ++){
				if ((arr1[e] is String  &&  arr2[e] is String) ||
					(arr1[e] is Number  &&  arr2[e] is Number)){
					if (arr1[e] != arr2[e]){
						return false;
					}
				} else if (arr1[e] is Character  &&  arr2[e] is Character){
					if (((arr1[e] as Character).symbol == "*"  ||  (arr1[e] as Character).symbol == "·"  ||  (arr1[e] as Character).symbol == "×")  &&
						((arr2[e] as Character).symbol == "*"  ||  (arr2[e] as Character).symbol == "·"  ||  (arr2[e] as Character).symbol == "×") )
						return true;
					if (((arr1[e] as Character).symbol == "/"  ||  (arr1[e] as Character).symbol == ":"  ||  (arr1[e] as Character).symbol == "÷")  &&
						((arr2[e] as Character).symbol == "/"  ||  (arr2[e] as Character).symbol == ":"  ||  (arr2[e] as Character).symbol == "÷") )
						return true; 
					if ((arr1[e] as Character).code != (arr2[e] as Character).code){
						return false;
					}
				}
			} 
			
			return true;
		}

	}
}
